<!DOCTYPE html>
<html lang="zh-CN" style="height: 100%">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>城内网--智慧校园</title>
    <link rel="Shortcut Icon" href="./images/logo.png" />
    <meta name="description" content="本网是针对学生的生活平台，包括学习、考试、交友、交流、商城" />
    <meta name="keywords" content="城内,城内网,智慧大学,智慧校园,在线教学,考勤系统,毕业设计" />
    <link href="{$Think.const.CSS_URL}common.css" rel="stylesheet" />
    <link rel="stylesheet" href="/layui/css/layui.css" media="all" />
    <script src="{$Think.const.JS_URL}jquery-1.12.3.min.js"></script>
    <script src="/layui/layui.js" charset="utf-8"></script>
    <script src="{$Think.const.JS_URL}common.js"></script>

    <script>
        opencookie();
        //退出
        function logout() {
            $.ajax({
                type: 'get',
                url: "{:url('index/my/logout')}",
                dataType: 'text',
                data: {},
                success: function (data) {
                    parent.location.href = "{:url('index/my/index')}";
                },
            });
        }
    </script>

    <script>
        layui.use('element', function () {
            var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块

            //监听导航点击
            element.on('nav(demo)', function (elem) {
                //console.log(elem)
                layer.msg(elem.text());
            });
        });
    </script>

    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <!--[if lte IE 9]>
            <script src="{$Think.const.JS_URL}respond.js"></script>
            <script src="{$Think.const.JS_URL}html5shiv.js"></script>
        <![endif]-->

    <!--[if lt IE 8]>
            <script>
                alert('IE浏览器版本过低，请下载并使用官方提供的google浏览器');
                window.location.href = 'http://www.chengneiwang.com/public/static/chrome_xp_installer.rar';
            </script>
        <![endif]-->
    <style>
        html,
        body {
            height: 100%;
        }
    </style>
</head>

<body>
    <!-- 顶部菜单 -->
    <ul class="layui-nav">
        <li class="layui-nav-item">
            <a href="{:url('index/score/index')}"><span style="font-size: 1.5em">成绩管理系统</span></a>
        </li>

        <li class="layui-nav-item">
            <a href="#">
                【
                <span id="title000">广东工业大学华立学院</span>
                】
            </a>
        </li>

        <li class="layui-nav-item" style="margin-left: 200px">
            <a href="{:url('index/score/index')}">首页</a>
        </li>

        <li class="layui-nav-item">
            <!-- <a href="{:url('index/score/result_input')}">成绩录入</a> -->
            <a href="{:url('index/score/course_manage')}">成绩录入</a>
        </li>



        {if condition="session('uid') eq null "}
        <li class="layui-nav-item" style="float: right"><a href="#">注册</a></li>
        <li class="layui-nav-item" style="float: right"><a href="{:url('my/login')}">登录</a></li>
        {else /}
        <li class="layui-nav-item" style="float: right; margin-right: 50px">
            <a href="#" onclick="logout()">退出</a>
        </li>
        <li class="layui-nav-item" style="float: right">
            <a href="#">
                <i class="layui-icon layui-icon-friends"></i>
                {switch name=session('userclass')} {case value="2" break 1}教务处{/case} {case value="1" break 1}{php}echo
                session('truename'){/php}.学院{/case} {case value="3" break 1}教师{/case} {case value="4"}{php}echo session('truename'){/php}.同学{/case}
                {case value="0"}{php}echo session('truename'){/php}.管理员{/case} {/switch}
            </a>
        </li>
        {/if}
    </ul>

    <div class="layui-container-fluid">
        <div class="container-fluid">
            <div class="layui-card">
                <div class="layui-card-body">
                    <span class="from-title">{$nowClass.class_name}</span>
                    <label>({$kechengdata.coursename})</label>
                    <ul class="layui-nav nav-select">
                        <li class="layui-nav-item">
                            <a href="javascript:;">{$nowClass.class_name}</a>
                            <dl class="layui-nav-child">
                                {volist name='classData' id='classData'}
                                <dd>
                                    <a href="{:url('index/score/result_input')}?banjiid={$classData.banjiid}&kechengid={$classData.kechengid}">{$classData.class_name}</a>
                                </dd>
                                {/volist}
                            </dl>
                        </li>
                    </ul>
                        <!-- 表格数据查询块 -->

                    <!-- 表格 -->
                    <table class="layui-hide" id="testTable" lay-filter="tableOption"></table>
                    <!-- 表格工具 -->
                    <script type="text/html" id="toolbarDemo">
                            <div class="layui-btn-container" >
                                {if session('userclass') == '10'}
                                <button class="layui-btn layui-btn-sm" lay-event="add">录入成绩</button>
                                <button class="layui-btn layui-btn-sm" lay-event="batchdel">批量删除</button>
                                {/if}
                                <!-- <button class="layui-btn layui-btn-sm" lay-event="import">导入成绩</button> -->
                                <button class="layui-btn layui-btn-sm" lay-event="percentage">设置各成绩占比</button>
                                <button class="layui-btn layui-btn-sm" lay-event="finish">完成录入</button>
                            </div>
                        </script>
                    <script type="text/html" id="barDemo">
                            {if session('userclass') == '1'} {{# if(d.check1 != 0){ }}
                            <a class="layui-btn layui-btn-xs layui-btn-normal">已审核</a>
                            {{# } else { }}
                            <a class="layui-btn layui-btn-xs" lay-event="check">审核</a>
                            {{# } }} {elseif session('userclass') == '2' /} {{# if(d.check2 != 0){ }}
                            <a class="layui-btn layui-btn-xs layui-btn-normal">已审核</a>
                            {{# } else { }}
                            <a class="layui-btn layui-btn-xs" lay-event="check">审核</a>
                            {{# } }} {/if}
                            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                        </script>
                    <!-- 弹出模板框 -->
                    <div class="margin-top30 J-percentage is-hidden">
                        <form class="layui-form layui-fluid J-add-form" lay-filter="formTest">
                            <input type="hidden" class="form-control" id="id" name="scoreid" value="" placeholder="请输入内容" />
                            <input type="hidden" class="form-control" id="schoolid" name="schoolid" value="99" placeholder="请输入内容" />
                            <div class="layui-form-item">
                                <label class="layui-form-label">平时成绩</label>
                                <div class="layui-input-block">
                                    <input type="number" value="30" max="100" min="0" class="layui-input media-input" id="usualRate"
                                        placeholder="请输入内容" />
                                    %
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">考试成绩</label>
                                <div class="layui-input-block">
                                    <input type="number" value="70" min="0" max="100" class="layui-input media-input" id="testRate"
                                        placeholder="请输入内容" />
                                    %
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">实践成绩</label>
                                <div class="layui-input-block">
                                    <input type="number" value="0" max="100" min="0" class="layui-input media-input" id="practRate"
                                        placeholder="请输入内容" />
                                    %
                                </div>
                                <label for="">提示：总占比不超过100%</label>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        //用选择的学校名替换“城内网”
        nowselectedschoolid = getCookie('nowselectedschoolid');
        nowselectedschoolname = getCookie('nowselectedschoolname');
        if (nowselectedschoolid == 0 || nowselectedschoolid == undefined || nowselectedschoolid == null) {
            $('#title000').text('广东工业大学华立学院');
        } else {
            $('#title000').text(nowselectedschoolname);
        }
    </script>

    <script>
        var scorePercentage = {};
        $(function () {
            initClass('courselist');
            initTable();
            layuiDate('.J-date');
            scorePercentage = {
                usualRate: parseInt($('#usualRate').val()),
                testRate: parseInt($('#testRate').val()),
                practRate: parseInt($('#practRate').val()),
            };
        });

        function initTable() {
            var table;
            // 请求路径
            var requireUrl = {
                add: "{:url('score/result_input_add')}?banjiid=" + getUrlVariable('banjiid') + '&kechengid=' + getUrlVariable('kechengid'),
                edit: "{:url('score/result_input_edit')}?banjiid=" + getUrlVariable('banjiid') + '&kechengid=' + getUrlVariable('kechengid'),
                remove: "{:url('score/result_input_remove')}",
                list: "{:url('score/get_result_input_list')}?banjiid=" + getUrlVariable('banjiid') + '&kechengid=' + getUrlVariable('kechengid'),
                check: "{:url('score/result_check')}",
                finish: "{:url('score/finishInput')}"
            };

            layui.use('table', function () {
                table = layui.table;
                table.render({
                    elem: '#testTable',
                    url: requireUrl.list,
                    toolbar: '#toolbarDemo',
                    title: '考试课程',
                    totalRow: false,
                    cols: [
                        [
                            {
                                type: 'checkbox',
                                fixed: 'left',
                                align: 'center',
                                minWidth: '100',
                            },
                            {
                                field: 'id',
                                title: 'ID',
                                align: 'center',
                                minWidth: '100',
                            },
                            {
                                field: 'student_no',
                                title: '学号',
                                align: 'center',
                                minWidth: '100',
                            },
                            {
                                field: 'studentname',
                                title: '姓名',
                                align: 'center',
                                minWidth: '100',
                            },
                            {
                                field: 'usual_score',
                                title: '平时成绩',
                                align: 'center',
                                minWidth: '100',
                                edit: 'text',
                            },
                            {
                                field: 'test_score',
                                title: '考试成绩',
                                align: 'center',
                                minWidth: '100',
                                edit: 'text',
                            },
                            {
                                field: 'practice_score',
                                title: '实践成绩',
                                align: 'center',
                                minWidth: '100',
                                edit: 'text',
                            },
                            {
                                field: 'total_score',
                                title: '总成绩',
                                align: 'center',
                                minWidth: '120',
                            },
                            // {
                            //     field: 'check1',
                            //     title: '学院审核',
                            //     align: 'center',
                            //     minWidth: '100',
                            //     templet: function (d) {
                            //         var result;
                            //         if (d.check1 == 0) result = '<span class="green">未审核</span>';
                            //         if (d.check1 == 1) result = '<span class="red">不通过</span>';
                            //         if (d.check1 == 2) result = '<span class="red">通过</span>';
                            //         return result;
                            //     },
                            // },
                            // {
                            //     field: 'check2',
                            //     title: '教务处审核',
                            //     align: 'center',
                            //     minWidth: '100',
                            //     templet: function (d) {
                            //         var result;
                            //         if (d.check2 == 0) result = '<span class="green">未审核</span>';
                            //         if (d.check2 == 1) result = '<span class="red">不通过<不通过/span>';
                            //         if (d.check2 == 2) result = '<span class="red">通过</span>';
                            //         return result;
                            //     },
                            // },
                            {
                                field: 'create_time',
                                title: '时间',
                                align: 'center',
                                minWidth: '120',
                            },
                            {
                                fixed: 'right',
                                title: '操作',
                                toolbar: '#barDemo',
                            },
                        ],
                    ],
                    id: 'testReload',
                    page: true,
                    parseData: function (res) {
                        return {
                            code: 0,
                            msg: '',
                            count: res.length,
                            data: res,
                        };
                    },
                });
                table.on('edit(tableOption)', function (obj) {
                    if (obj.value > 100) {
                        layer.msg('分数不能大于100', { icon: 7 });
                        return;
                    }

                    var re = /^\d+$/;//判断字符串是否为数字//判断正整数/[1−9]+[0−9]∗]∗/
                    if (!re.test(obj.value)) {
                        layer.msg('请输入数字', { icon: 7 });
                        return;
                    }

                    var endScore = [];
                    switch (obj.field) {
                        case 'usual_score':
                            endScore[0] = obj.value * scorePercentage.usualRate * 0.01;
                            endScore[1] = obj.data.test_score * scorePercentage.testRate * 0.01;
                            endScore[2] = obj.data.practice_score * scorePercentage.practRate * 0.01;
                            break;
                        case 'test_score':
                            endScore[0] = obj.value * scorePercentage.testRate * 0.01;
                            endScore[1] = obj.data.usual_score * scorePercentage.usualRate * 0.01;
                            endScore[2] = obj.data.practice_score * scorePercentage.practRate * 0.01;
                            break;
                        case 'practice_score':
                            endScore[0] = obj.value * scorePercentage.practRate * 0.01;
                            endScore[1] = obj.data.usual_score * scorePercentage.usualRate * 0.01;
                            endScore[2] = obj.data.test_score * scorePercentage.testRate * 0.01;
                            break;
                    }
                    obj.data.total_score = endScore.reduce(function (prev, next, index, array) {
                        return prev + next;
                    });

                    var userInfo = {
                        id: obj.data.id,
                        schoolid: obj.data.schoolid,
                        banjiid: obj.data.banjiid,
                        teacherId: obj.data.teacherId,
                        term: obj.data.term,
                        kechengid: obj.data.kechengid,
                        studentid: obj.data.studentid,
                        usual_score: obj.data.usual_score,
                        test_score: obj.data.test_score,
                        practice_score: obj.data.practice_score,
                        total_score: obj.data.total_score,
                    };

                    var url = "{:url('score/result_input_modify')}";
                    ajaxRequest('post', url, userInfo, function (data) {
                        var errMesage = data.msg ? data.msg : data;
                        // data.code == 1 ? successTrip(data) : errorAlert(false, errMesage);
                        // parent.location.reload();
                        table.reload(
                        'testReload',
                        {
                            page: {
                                curr: 1, //重新从第 1 页开始
                            },
                        },
                        'data'
                    );
                    });
                });

                //工具栏事件
                table.on('toolbar(tableOption)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'add':
                            //  layerOpenInit('考试任务编辑',requireUrl.add)
                            layer.open({
                                type: 2,
                                title: '添加',
                                // skin: 'layui-layer-rim', //加上边框
                                area: ['800px', '620px'], //宽高
                                content: requireUrl.add,
                            });
                            break;
                        case 'batchdel':
                            tableBatchDel(checkStatus, requireUrl.remove);
                            break;
                        case 'percentage':
                            layerOpenInit(
                                {
                                    title: '设置成绩比例',
                                    width: '400px',
                                },
                                $('.J-percentage'),
                                function (index) {
                                    // 通过操作
                                    scorePercentage = {
                                        usualRate: parseInt($('#usualRate').val()),
                                        testRate: parseInt($('#testRate').val()),
                                        practRate: parseInt($('#practRate').val()),
                                    };
                                    var sum = scorePercentage.usualRate + scorePercentage.testRate + scorePercentage.practRate;

                                    if (sum > 100) {
                                        layer.msg('总和不能超过100%', { icon: 5 });
                                        return;
                                    }

                                    layer.msg('设置成功', { icon: 6 });
                                    localStorage.setItem('ScorePercentage', JSON.stringify(scorePercentage));
                                }
                            );
                            // setPercentage(checkStatus, requireUrl.remove);
                            break;
                        case 'finish':
                            var params = {
                                kechengid: getUrlVariable('kechengid'),
                                banjiid: getUrlVariable('banjiid'),
                                input_state: 1
                            }

                            layerConfirm(requireUrl.finish, params, "是否已经完成成绩录入？", "确认", "post");
                            break;
                    }
                });

                //监听行工具事件
                table.on('tool(tableOption)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'del') {
                        layerConfirm(requireUrl.remove, {
                            id: data.id,
                        });
                    } else if (obj.event === 'edit') {
                        // 编辑
                        layer.open({
                            type: 2,
                            title: '添加',
                            // skin: 'layui-layer-rim', //加上边框
                            area: ['800px', '620px'], //宽高
                            content: requireUrl.edit + '&id=' + data.id,
                        });
                    } else if (obj.event === 'check') {
                        // 审核
                        var data = {
                            id: data.id,
                        };
                        layerOpenInit(
                            {
                                title: '审核',
                                btnTitle: ['通过', '不通过'],
                            },
                            $('.J-temple'),
                            function (index) {
                                // 通过操作
                                data.check = 1;
                                ajaxRequest('post', requireUrl.check, data, function (data) {
                                    data.code == 1 ? successTrip(data) : errorAlert(false, data.msg);
                                });
                            },
                            function () {
                                // 弹出后的回调
                                ajaxRequest('get', requireUrl.edit, { id: data.id }, function (res) {
                                    form.val('formTest', res.data);
                                });
                            },
                            function (index) {
                                // 不通过
                                data.check = 2;
                                ajaxRequest('post', requireUrl.check, data, function (data) {
                                    data.code == 1 ? successTrip(data) : errorAlert(false, data.msg);
                                });
                            }
                        );
                    }
                });
            });

            // 搜索重置操作
            var active = {
                reload: function () {
                    var queryParams = serializeObject($('.J-search-form'));
                    console.log(queryParams);
                    //执行重载
                    table.reload(
                        'testReload',
                        {
                            page: {
                                curr: 1, //重新从第 1 页开始
                            },
                            where: queryParams,
                        },
                        'data'
                    );
                },
            };
            $('.J-search').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            $('.J-reload').on('click', function () {
                $('.J-query-params').val('');
                form.render('select');
                active.reload ? active.reload.call(this) : '';
            });
        }
    </script>

    {include file="my/footer"}
</body>

</html>